<?php
	
	//obsluga wyjatkow i logowanie do pliku
	class CExceptionBase
	{
		static function &GetInstance()
		{
			global $g_hObjects;
			static $m_hApp = NULL;
						 
			if(!isset($m_hApp))
			{
				$m_hApp = new CExceptionBase();					 
				$g_hObjects[] = $m_hApp;
				$m_hApp->OnInit();
			}
			
			return $m_hApp;
		}

		function OnInit()
		{	
			set_exception_handler( array(&$this,'UserExceptionHandler') );
		}
		
		function OnDestroy()
		{
			
		}

		function UserExceptionHandler($exception)
		{
			echo "Wystapil  wyjatek <br><br>";	
		
			$szTime = date("d-m-Y H:i:s");
			
			$hFile = fopen(LOG_DIR.'/exception.log',"a+");
			
			if($hFile == FALSE)
			{
				$szMsg = "Klasa: ".get_class($exception)."<br/>";
				$szMsg.= "$szTime => unable to save error to log file! <br>";
				$szMsg.= "$szTime => msg: ".$exception->getMessage()." <br><br>";
				
				echo $szMsg;
			}
			else
			{	
				$szMsg = "$szTime => klasa: ".get_class($exception)."\n\n";
				$szMsg.= "$szTime => msg: ".$exception->getMessage()." \n\n";
				
				fwrite($hFile,$szMsg);
				fclose($hFile);
			}
		}
	}

	//installing exception base
	CExceptionBase::GetInstance();	

?>